package com.cxb.apiDriver.service;

import com.cxb.apiDriver.remote.ServiceDriverUserClient;
import com.cxb.apiDriver.remote.ServiceMapClient;
import com.cxb.internalcommon.dto.Car;
import com.cxb.internalcommon.dto.ResponseResult;
import com.cxb.internalcommon.request.ApiDriverPointRequest;
import com.cxb.internalcommon.request.PointDTO;
import com.cxb.internalcommon.request.PointRequestDTO;
import com.cxb.internalcommon.responese.DriverUserExistsResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PointService {

    @Autowired
    private ServiceDriverUserClient serviceDriverUserClient;

    @Autowired
    private ServiceMapClient serviceMapClient;
    public ResponseResult upload(ApiDriverPointRequest apiDriverPointRequest){

        Long carId = apiDriverPointRequest.getCarId();

        //通过carId获取tid,trid
        ResponseResult<Car> Id = serviceDriverUserClient.getCarById(carId);
        Car car = Id.getData();
        String tid = car.getTid();
        String trid = car.getTrid();

        //调用地图上传
        PointDTO[] points = apiDriverPointRequest.getPoints();
        PointRequestDTO pointRequestDTO = new PointRequestDTO();
        pointRequestDTO.setTid(tid);
        pointRequestDTO.setTrid(trid);
        pointRequestDTO.setPoints(points);

        return serviceMapClient.upload(pointRequestDTO);
    }
}
